import Vue from 'vue';
export default {
    //获取店铺主页信息
    /*
    * obj:{
    *   userId:0,//用户Id
    *   storeId:0,//店铺Id
    * }
    * 结果
    * {
        "success": true,
        "errMsg": null,
        "result": {
            "name": "王者动物园",
            "logo": "http://asd/fghjsd.jpg",
            "concerned":true,               ---------是否已关注
            "praiseRate": "90%",            ---------显示的好评率 为null或''则不显示   --将废弃！！！--
            "evaluateLevel": "4.6",         ---------店铺平均评价星级  ++20191206++
            "latitude":"34.155",            ---------纬度  ++20190828++
            "longitude":"120.5",            ---------经度  ++20190828++
            "industry":"婚纱摄影",          ---------店铺所属行业类型  ++20191126++
            "userCartItemNum":12            ---------用户购物车商品总数  ++20191126++
        }
    }
    * */
    merStoreGetStoreInfo (state, obj) {
        if (!obj) {
            return
        }
        let that = this;
        let userId = this.getters.currentUserFn && this.getters.currentUserFn.userId ? this.getters.currentUserFn.userId : 0;
        let storeId = this.getters.currentStoreFn && this.getters.currentStoreFn.storeId ? this.getters.currentStoreFn.storeId : 0;
        let thirdId = this.getters.currentThirdFn && this.getters.currentThirdFn.thirdId ? this.getters.currentThirdFn.thirdId : 0;
        let params = {
            thirdId: obj.thirdId || thirdId,
        }
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/store/${obj.storeId || storeId}/home/info/user/${obj.userId || userId}`;
        Vue.prototype.xurl.get(url, params).then(data => {
            if (data.success) {
                if (obj && obj.success && typeof obj.success == 'function') {
                    let tempObj = {
                        storeId: obj.storeId || storeId
                    }
                    tempObj = Object.assign({}, tempObj, data.result)
                    that.commit('updateCurrentStore', tempObj);
                    if (obj.success) {
                        obj.success(data.result);
                    }
                }
            } else if (data.errMsg) {
                if (obj && obj.fail && typeof obj.fail == 'function') {
                    obj.fail(data);
                } else if (obj.toast) {
                    Vue.$toast({ message: data.errMsg });
                } else {
                    console.log(data.errMsg);
                }
            } else {
                if (obj.failText) {
                    Vue.$toast({ message: obj.failText });
                }
            }
        })
    },
    //模糊查询店铺列表
    /*
    * obj:{
    *   userId:0,//用户Id
    *   storeId:0,//店铺Id
    * }
    * 结果
    * {
        "success": true,
        "errMsg": null,
        "result": {
            "name": "王者动物园",
            "logo": "http://asd/fghjsd.jpg",
            "concerned":true,               ---------是否已关注
            "praiseRate": "90%",            ---------显示的好评率 为null或''则不显示   --将废弃！！！--
            "evaluateLevel": "4.6",         ---------店铺平均评价星级  ++20191206++
            "latitude":"34.155",            ---------纬度  ++20190828++
            "longitude":"120.5",            ---------经度  ++20190828++
            "industry":"婚纱摄影",          ---------店铺所属行业类型  ++20191126++
            "userCartItemNum":12            ---------用户购物车商品总数  ++20191126++
        }
    }
    * */
    merStoreGetStoreList (state, obj, callbacks) {
        if (!obj) {
            return
        }
        let storeId = obj.storeId || 0;
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/store/list`;
        this.xurl.get(url).then(data => {
            if (data.success) {
                if (callbacks && callbacks.success && typeof callbacks.success == 'function') {
                    callbacks.success();
                }
            } else if (data.errMsg) {
                Vue.$toast({ message: data.errMsg });
            } else {
                if (obj.failText) {
                    Vue.$toast({ message: obj.failText });
                }
            }
        })
    },
    /*买家秀*/
    buyShowApi (state, obj) {
        let storeId = this.getters.currentStoreFn && this.getters.currentStoreFn.storeId ? this.getters.currentStoreFn.storeId : 0;
        let params = {
            'userId': Vue.prototype.userId,
            "pageNum": obj && obj.pageNum ? obj.pageNum : 1,
            "pageSize": obj && obj.pageSize ? obj.pageSize : 5,
            'headId': obj && obj.shareId ? obj.shareId : 0
        }
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/store/${obj && obj.storeId ? obj.storeId : storeId}/buyer/show/list`;
        Vue.prototype.xurl.get(url, params).then(async data => {
            if (data.success) {
                await this.commit('dealBuyShow', data);
                if (obj && obj.successFn) {
                    obj.successFn();
                }
            } else if (data.errMsg) {
                console.log(data.errMsg);
            } else {
                console.log('获取买家秀接口失败');
            }
        })
    },
    /*纯媒体（实景）*/
    medioApi (state, obj) {
        let storeId = this.getters.currentStoreFn && this.getters.currentStoreFn.storeId ? this.getters.currentStoreFn.storeId : 0;
        let params = {
            storeId: obj && obj.storeId ? obj.storeId : (storeId || 0),
            menuId: obj && obj.menuId ? obj.menuId : 0,
            queryUserId: obj && obj.queryUserId ? obj.queryUserId : 0
        }
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/store/website/media/info`;
        Vue.prototype.xurl.getLoading(url, params).then(data => {
            if (data.success) {
                if (obj && obj.successFn) {
                    obj.successFn(data);
                }
            } else if (data.errMsg) {
                console.log(data.errMsg);
            } else {
                console.log('获取买家秀接口失败');
            }
        })
    },
    //   客服列表数据
    setCustomerList (state, val) {
        state.customerList = val
    },
    //   显示客服列表
    setShowCustomerList (state, val) {
        state.showCustomerList = val
    },
}